/*
 * @Description:
 * @Author: Zzt
 * @Date: 2022-11-10 16:49:18
 * @LastEditTime: 2022-11-17 17:04:21
 */
import { createContext, useReducer, useEffect, useContext } from 'react';
import { SET_CHART_TYPE, SET_X_DATA, SET_Y_DATA } from '../constants';
import { BasicsVisualizationReducer } from '../reducers/BasicsVisualizationReducer';
const initialState = {
  xdata: [],
  ydata: [],
  chartType: 2
};
const BasicsVisualizationContext = createContext();
const BasicsVisualizationContextProvider = (props) => {
  const [state, dispatch] = useReducer(BasicsVisualizationReducer, initialState);
  const actions = {
    setChartType(data) {
      dispatch({ type: SET_CHART_TYPE, data });
    },
    setXData(data) {
      dispatch({ type: SET_X_DATA, data });
    },
    setYData(data) {
      dispatch({ type: SET_Y_DATA, data });
    }
  };
  useEffect(() => {}, []);
  return (
    <BasicsVisualizationContext.Provider value={{ ...state, ...actions }}>
      {props.children}
    </BasicsVisualizationContext.Provider>
  );
};
export const useBasicsVisualizationContext = () => {
  return useContext(BasicsVisualizationContext);
};
export { BasicsVisualizationContext, BasicsVisualizationContextProvider };
